﻿#region References
using System;
using System.Collections.Generic;
using System.Collections;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using JigLibX.Physics;
using JigLibX.Geometry;
using JigLibX.Collision;
using Xen;
using Xen.Camera;
using Xen.Graphics;
using Xen.Input.State;
using Xen.Ex.Material;
using Xen.Graphics.State;
using Xen.Ex.Graphics.Content;
using Xen.Ex.Graphics;
using Xen.Ex.Graphics2D;
#endregion

namespace Ness.Engine.Graphics
{
    /// <summary>
    /// A list which stores the engine's lights, also handles addition/removing of lights
    /// </summary>
    class Lighting
    {
        #region Private Variables
        private MaterialLightCollection lights;
        #endregion

        /// <summary>
        /// Initialises the lighting class
        /// </summary>
        public Lighting()
        {
            lights = new MaterialLightCollection();
            SetupAmbientLight(new Vector3(2, 2, 2), new Vector3(-1, -1, 0));
        }

        /// <summary>
        /// Returns the light collection as MaterialLightCollection
        /// </summary>
        /// <returns>MaterialLightCollection lights</returns>
        public MaterialLightCollection GetList()
        {
            return lights;
        }

        /// <summary>
        /// Sets up the ambient lighting of the scene
        /// </summary>
        /// <param name="colour">Vector3 of the colour (R,G,B)</param>
        /// <param name="direction">Vector3 light diection</param>
        public void SetupAmbientLight(Vector3 colour, Vector3 direction)
        {
            lights.LightingEnabled = true;
            lights.AmbientLightColour = colour;
            lights.AddDirectionalLight(false, direction, colour);
        }

        /// <summary>
        /// Creates a light and adds it to the list
        /// </summary>
        /// <param name="lightPosition"></param>
        /// <param name="lightColor"></param>
        /// <param name="lightSpecularColour"></param>
        /// <param name="lightHalfFalloffDistance"></param>
        /// <param name="perPixel"></param>
        /// <returns></returns>
        public IMaterialPointLight CreateLight(Vector3 lightPosition, Color lightColor, Color lightSpecularColour, float lightHalfFalloffDistance, bool perPixel)
        {
            return lights.AddPointLight(perPixel, lightPosition, lightHalfFalloffDistance, lightColor, lightSpecularColour);
        }

        /// <summary>
        /// Resets the scenes lighting to nothing (all models will be black)
        /// </summary>
        public void ResetLighting()
        {
            lights = new MaterialLightCollection();
        }
    }
}
